'''
Cocoa-based socket server, speech, and sound for OS X 10.5 and higher.

Copyright (c) 2008 Carolina Computer Assistive Technology

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
'''
from ..server import JSONServer
from common.audio.page import PageController
from channel import ChannelController
from PyObjCTools import AppHelper

def buildServer(module, port):
    return JSONServer.alloc().initWithPort_(port)

def buildPage(module, page_id):
    return PageController(page_id, module)

def buildChannel(module, ch_id):
    return ChannelController.alloc().initWithId_(ch_id)

def run(module):
    # enter the main event loop
    AppHelper.runConsoleEventLoop()

def shutdown(module):
    AppHelper.stopEventLoop()
